package com.test.exception;

import com.test.constant.ErrCode;
import com.test.tool.StringTool;
import lombok.Getter;
import lombok.Setter;

/**
 * Created by andy on 16/08/15.
 */
public class MyRuntimeException extends RuntimeException {

    @Getter
    @Setter
    private ErrCode errCode = ErrCode.INTERNAL_ERR;

    public MyRuntimeException() {
        super(ErrCode.INTERNAL_ERR.info());
    }

    public MyRuntimeException(String message) {
        super(message);
    }

    public MyRuntimeException(String format, Object... arguments) {
        super(StringTool.formatString(format, arguments));
    }

    public MyRuntimeException(ErrCode errCode) {
        super(errCode == null ? "Error" : errCode.info());
        if (errCode != null)
            this.setErrCode(errCode);
    }

    public MyRuntimeException(ErrCode errCode, String message) {
        super(message);
        if (errCode != null)
            this.setErrCode(errCode);
    }

    public MyRuntimeException(ErrCode errCode, String format, Object... arguments) {
        super(StringTool.formatString(format, arguments));
        if (errCode != null)
            this.setErrCode(errCode);
    }
}
